package com.h6.crm.util.pojo;

import com.alibaba.ttl.TransmittableThreadLocal;
import com.h6.crm.entity.SysUser;

/**
 * 用户上下文
 *
 */
public class UserContext {

    /**
     * User holder
     */
    private static final TransmittableThreadLocal<SysUser> CURRENT_USER_HOLDER = new TransmittableThreadLocal<>();

    /**
     * 保存 Session
     *
     */
    public static void saveUser(SysUser user) {
        CURRENT_USER_HOLDER.set(user);
    }

    /**
     * 当前用户
     *
     */
    public static SysUser currentUser() {
        return CURRENT_USER_HOLDER.get();
    }

    /**
     * 删除 Session
     *
     */
    public static void removeUser() {
        CURRENT_USER_HOLDER.remove();
    }
}
